<?php App::import('Sanitize'); ?>
<div class="breadcrumbs">		
	<?php
	$items = array(
		array('Home', array('controller' => 'pitches', 'action' => 'index')),
		array('Opdrachten', array('controller' => 'pitches', 'action' => 'index')),
		array($this->FixText->fix_text(Sanitize::html($design['Pitch']['title']), 15, TRUE), array('controller' => 'pitches', 'action' => 'view', $design['Pitch']['id'] )),
		array('Ontwerpen', array('controller' => 'designs', 'action' => 'index', $design['Design']['pitch_id'])),
		array($this->FixText->fix_text(Sanitize::html($design['Design']['name']), 25, TRUE), array('controller' => 'design', 'action' => 'index', Sanitize::html($design['Design']['name'])))
	);
	echo $this->Navigation->breadcrumbs($items);
	?>
</div>
<div class="welcome"><h2>Ontwerp van <?php echo $this->Html->link(Sanitize::html($design['User']['DesignerProfile']['first_name']) . " " . Sanitize::html($design['User']['DesignerProfile']['insertion']) . " " . Sanitize::html($design['User']['DesignerProfile']['last_name']), array('controller' => 'designer_profiles', 'action' => 'view', $design['User']['DesignerProfile']['id'])); ?></h2></div>
				<div class="content-wrapper ui-corner-all">				
					<div class="block-white-top ui-corner-tl ui-corner-tr">
					<div class="clear"></div>
						<div class="brief-detail">
						
						<?php foreach($design['DesignPhoto'] as $photo):
						echo $this->Html->image($photo['file'], array('class'=>'preview'));
						endforeach;
						?>
						
						<div class="clear"></div>
						
						<h2>Motivatie</h2>
							<?php if ($design['showComments'] == 0) {
									echo '</br><p>U heeft geen toegang om verdere informatie te bekijken.</p>';
							} else {
								echo '<p>' . Sanitize::html($design['Design']['motivation']) . '</p>';
							} ?>
						</div>					
						<?php 
						if ($design['showComments'] == 1 ){ 
							foreach($design['Comment'] as $comment): 
								$userGroup = $comment["User"]["group_id"];
						
								if($userGroup == 1) { 
									$name = $comment["User"]["DesignerProfile"]["first_name"] . " " . $comment["User"]["DesignerProfile"]["insertion"] . " " . $comment["User"]["DesignerProfile"]["last_name"];
									if (isset($comment["User"]["DesignerProfile"]["avatar"])){
										$avatar = $comment["User"]["DesignerProfile"]["avatar"];
										}else{
											$avatar = "default_avatar.png";
										}
									}else{
										$name = $comment["User"]["ContractorProfile"]["first_name"] . " " . $comment["User"]["ContractorProfile"]["insertion"] . " " . $comment["User"]["ContractorProfile"]["last_name"];
									if (isset($comment["User"]["ContractorProfile"]["avatar"])){
										$avatar = $comment["User"]["ContractorProfile"]["avatar"];
										}else{
											$avatar = "default_avatar.png";
										}
									}
						?>
						
						<div class="reactie-container">
							<div class="poster-avatar">
							<?php 
							if ($userGroup == 1 ) { 
							echo $this->Html->link($this->Html->image(Sanitize::html($avatar)), array('controller' => 'designer_profiles', 'action' => 'view', $comment['User']['DesignerProfile']['id']), array('escape' => false));
							} else {
							echo $this->Html->link($this->Html->image(Sanitize::html($avatar)), array('controller' => 'contractor_profiles', 'action' => 'view', $comment['User']['ContractorProfile']['id']), array('escape' => false));
							}
							?>
							</div>
								<div class="poster-reactie">
									<div class="poster-body">
										<?php 
											$dingen = array('\n', '\\');
											$replace = array('<br />',  '');
										?>
										<?php echo str_replace($dingen, $replace, Sanitize::html($comment['body'])); ?>
									</div>
										<?php if ($comment["User"]['id'] == $_SESSION['Auth']['User']['id']) { ?>
										<div class="comment-action-container">
											<div class="delete">
												<?php
												$id = $comment['id'];
												echo $this->Html->link(' ', array('controller' => 'comments', 'action' => 'delete', $id, $design['Design']['id']));
												?>
												</div>
											<div class="edit">
												<?php
												$id = $comment['id'];
												echo $this->Html->link(' ', array('controller' => 'comments', 'action' => 'edit', $id, $design['Design']['id']));
												?>
											</div>
										</div>
										<?php } ?>
											<br />
												<div class="poster-stamp"><?php 
												if ($userGroup == 1 ) { 
												echo $this->Html->link(Sanitize::html($name), array('controller' => 'designer_profiles', 'action' => 'view', $comment['User']['DesignerProfile']['id'])); } else {
												echo $this->Html->link(Sanitize::html($name), array('controller' => 'contractor_profiles', 'action' => 'view', $comment['User']['ContractorProfile']['id']));
												}
												echo " " . $this->FixDate->fix_date($comment['modified'], "time"); ?>
												</div>
							
								</div>
						</div>
						<?php endforeach;  ?>
						<div class="reageren-container">
							<div class="reageren">
							<h1>Reageren</h1>
								<?php echo $this->Form->create('Comment',  array('action' => 'add')); ?>
								<?php echo $this->Form->textarea('body');?>
								<?php echo $this->Form->input('design_id', array('type' => 'hidden', 'value' => $this->params['pass'][0])); ?>
								<?php $options = array(
									'name' => '',
									'label' => 'Reageer',
		    						'class' => 'button-reageer',
								);
								echo $form->end($options,__('Plaatsen', true));  ?>
							</div>
							<div class="clear"></div>
						</div>
						<?php } ?>
					</div>
					
					
					<?php if ($design['showComments'] == 1) {
							echo '<div class="gray-bottom ui-corner-br ui-corner-bl">';
					} else {
						echo '<div class="white-bottom ui-corner-br ui-corner-bl">';
					} ?>
					</div>
				</div>
